package com.magenta.maxoptra.gis.util;

import org.jetbrains.annotations.Nullable;

public class Apis {

	private Apis() { }

    /**
     * @see Apis#cid(String, String, String...)
     */
    @Deprecated
	public static Long cid(String providerName, String versionApi) {
		return longHash(providerName) << 32 | longHash(versionApi);
	}

    public static Long cid(String providerName, String versionApi, @Nullable String... discriminators) {
        long baseHash = providerName != null ? providerName.hashCode() : 0;
        baseHash = 31 * baseHash + (versionApi != null ? versionApi.hashCode() : 0);

        long auxHash = 0;
        if (discriminators != null) {
            for (final String discriminator : discriminators) {
                auxHash = 31 * auxHash + (discriminator != null ? discriminator.hashCode() : 0);
            }
        }

        return auxHash << 32 | (baseHash & 0xFFFFFFFFL);
    }

	private static long longHash(Object obj) {
		return obj != null ? (long) obj.hashCode() : 0L;
	}
}
